!function (modules) {
    const moduleCache = {};

    function require(moduleId) {
        // 如果模块已经在缓存中，直接返回其导出内容
        if (moduleCache[moduleId]) return moduleCache[moduleId].exports;

        // 创建一个新的模块并放入缓存
        const module = moduleCache[moduleId] = {
            exports: {},
            id: moduleId,
            loaded: false
        };

        // 调用模块函数并传递module, module.exports和require
        modules[moduleId].call(module.exports, module, module.exports, require);

        // 标记模块为已加载
        module.loaded = true;

        // 返回模块的导出内容
        return module.exports;
    }

    // 存储模块定义
    require.m = modules;

    // 存储模块缓存
    require.c = moduleCache;

    // 设置公共路径（这里为空字符串）
    require.p = "";

    // 执行入口模块（假设入口模块的ID为"entry"）
    return require("entry");
}({
    // 导出入口模块 模块id为12
    "entry": function (module, exports, require) {
        module.exports = require("pageManager").init()
    },

    // 创建空对象
    "utils": function (module, exports, require) {
        const utils = {
            supportTouch: "ontouchstart" in document.documentElement,
            io: {},
        };

        // 序列化参数对象为URL查询字符串
        function serialize(params) {
            let key, result = [];
            const encode = encodeURIComponent;
            // 枚举
            for (key in params) {
                result.push(encode(String(key)) + "=" + encode(String(params[key])));
            }
            return result.join("&");
        }

        // 解析URL查询字符串为对象
        function parseUrl(query) {
            const queryString = query || location.search.substr(1);
            const params = {};
            queryString.split("&").forEach(function (pair) {
                const [key, value] = pair.split("=");
                params[key] = decodeURIComponent(value);
            });
            return params;
        }

        // 添加URL参数
        function addUrlParam(param, url) {
            url = url || window.location.href.split("#")[0];
            const paramString = typeof param === "object" ? serialize(param) : param;
            return url += (url.split("?")[1] ? "&" : "?") + paramString;
        }
        // 刷新验证码图片
        function refreshCaptcha() {
            const verifyImages = $(".verifyimg");
            if (verifyImages.length) {
                verifyImages.click();
            }
        }
        // 判断是否为移动设备
        utils.isMobile = {
            iOS: function () {
                return navigator.userAgent.match(/iPhone|iPad|iPod/i);
            },
        };
        // 将工具函数挂载到utils.io对象上
        utils.io.serialize = serialize;
        utils.io.parseUrl = parseUrl;
        utils.io.addUrlParam = addUrlParam;

        // 定义cookie操作函数
        !function (utils) {
            function getCookies() {
                const cookies = {};
                if (document.cookie) {
                    const cookieArray = document.cookie.split("; ");
                    cookieArray.forEach(function (cookie, e, o) {
                        const [key, value] = cookie.split("=");
                        cookies[key] = value;
                    })
                }
                return cookies
            }

            function getCookie(name) {
                return decodeURIComponent(getCookies()[name]) || null
            }

            function removeCookie(name) {
                getCookies()[name] && (document.cookie = name + "=; max-age=0")
            }

            function clearCookies() {
                const cookies = getCookies();
                for (const key in cookies) document.cookie = key + "=; max-age=0"
            }

            function getAllCookies(t) {
                return getCookies()
            }

            function noConflict(cookieName) {
                return cookieName && "string" == typeof cookieName ? cookieName && window.cookie ? (window[cookieName] = window.cookie, delete window.cookie, window[cookieName]) : void 0 : window.cookie
            }

            utils.cookie = {getCookies: getAllCookies, set: require, get: getCookie, remove: removeCookie, clear: clearCookies, noConflict: noConflict}
        }(utils);
        $(function () {

        }),
            utils.io.refreshChar = refreshCaptcha, module.exports = utils
    },

    "pageManager": function (module, exports, require) {
        let utils = require("utils"); // 引入工具模块
        let totalPages= 1; // 总页数
        let readingMode = ""; // 当前阅读模式（lr: 左右滑动, ud: 上下滑动）
        let currentPage = 1; // 当前页码
        let readingProgress = 0;  // 当前阅读进度
        let transformX = 0; // 当前页面的translateX值
        // 文本容器
        let textContainer = (window.location.href.split("?")[0].split("#")[0], $("#daan-novel-content"));
        let body = $("body"); // body元素

        /**
         * 处理左右滑动模式
         */
        function handleLeftRightMode() {
            readingMode = "lr";
            body.addClass("page-lr");
            adjustLayout();
        }

        /**
         * 处理上下滑动模式
         */
        function handleUpDownMode() {
            readingMode = "ud";
            currentPage = 1;
            body.removeClass("page-lr");
            textContainer.removeAttr("style");
        }

        /**
         * 设置CSS过渡效果
         * @param {HTMLElement} element - 目标元素
         * @param {number} duration - 过渡持续时间
         * @param {number|string} translateX - X轴位移
         * @param {number|string} translateY - Y轴位移
         * @param {function} callback - 回调函数
         */
        function setTransition(element, duration, translateX, translateY, callback) {
            $(element).css({
                "-webkit-transition": "-webkit-transform " + duration + "ms ease",
                "-o-transition": "-o-transform " + duration + "ms ease",
                "-moz-transition": "-moz-transform " + duration + "ms ease",
                "-ms-transition": "-ms-transform " + duration + "ms ease",
                "transition": "transform " + duration + "ms ease"
            });

            const xValue = typeof translateX === "number" ? translateX + "px" : translateX,
                yValue = typeof translateY === "number" ? translateY + "px" : translateY;

            $(element).css({
                "-webkit-transform": "translate3d(" + xValue + ", " + yValue + ",0)",
                "-moz-transform": "translate3d(" + xValue + ", " + yValue + ",0)",
                "-o-transform": "translate3d(" + xValue + ", " + yValue + ",0)",
                "-ms-transform": "translate3d(" + xValue + ", " + yValue + ",0)",
                "transform": "translate3d(" + xValue + ", " + yValue + ",0)"
            });

            if (typeof callback === "function") {
                setTimeout(callback, duration);
            }
        }

        /**
         * 设置页面位置
         * @param {number} pageNumber - 页面编号
         * @param {number} duration - 过渡持续时间
         */
        function setPagePosition(pageNumber, duration) {
            // 获取窗口宽度
            const windowWidth = $(window).width();

            // 获取文本元素的 ID
            const textElementId = "#daan-novel-content";

            // 确定目标页码，默认为当前页码
            const targetPage = pageNumber || currentPage;

            // 确定过渡持续时间，默认为 0
            const transitionDuration = duration || 0;

            // 计算 transformX 值
            transformX = -windowWidth * (targetPage - 1);


            // 获取文本元素的 jQuery 对象
            const textElement = $(textElementId);

            // 设置过渡效果
            setTransition(textElement, transitionDuration, transformX, 0, () => {
            });
        }

        /**
         * 适应页面布局
         * @param {number} progress - 阅读进度
         */
        function adjustLayout(progress = 0) {
            // 检查阅读模式是否为左右翻页模式
            if (readingMode === "lr") {
                const windowWidth = $(window).width(),
                    windowHeight = utils.isMobile.iOS() ? window.innerHeight : $(window).height();

                // 设置文本容器的高度和宽度
                textContainer.css({
                    height: windowHeight,
                    width: windowWidth
                });

                // 计算总页数
                const rdTxtElement = document.getElementById("daan-novel-content");
                totalPages = Math.ceil(rdTxtElement.scrollWidth / windowWidth);

                // 根据进度调整当前页码，并设置页面位置
                if (progress) {
                    currentPage = Math.max(Math.floor(progress * totalPages), 1);
                    setPagePosition(currentPage, 0);
                }

                // 确保页面滚动到顶部
                window.scrollTo(0, 1);
            }
        }

        /**
         * 向左翻页
         * @param {number} duration - 过渡持续时间
         */
        function flipLeft(duration = 400) {

            // 减少当前页码
            currentPage--;

            // 如果当前页码小于等于0，加载上一页
            if (currentPage <= 0) {
                currentPage = 1; // 重置当前页码为1
                android.turnPrevPage(); // 加载上一页
                return; // 提前返回
            }

            // 计算阅读进度
            readingProgress = (currentPage / totalPages).toFixed(2);

            // 设置页面位置
            setPagePosition(currentPage, duration);

            // 调整页面布局
            adjustLayout();
        }

        /**
         * 向右翻页
         * @param {number} duration - 过渡持续时间
         */
        function flipRight(duration = 400) {

            // 增加当前页码
            currentPage++;

            // 如果当前页码大于总页数，加载下一页
            if (currentPage > totalPages) {
                currentPage = totalPages; // 重置当前页码为总页数
                android.turnNextPage(); // 加载下一页
                return; // 提前返回
            }

            // 计算阅读进度
            readingProgress = (currentPage / totalPages).toFixed(2);

            // 设置页面位置
            setPagePosition(currentPage, duration);

            // 调整页面布局
            adjustLayout();
        }

        let parseUrl = utils.io.parseUrl;
        let pageManager = {
            init: function () {
                this.formatPage();
                return this;
            },
            /**
             * 格式化页面
             */
            formatPage: function () {
                const initialHash = "#__zrposed",
                    currentHash = window.location.hash,
                    queryParams =parseUrl(window.location.href.split("#")[1]),
                    isInitialHash = currentHash === initialHash;
                if (!isInitialHash) {
                    const prevParam = queryParams && queryParams.zref;
                    if (prevParam === "prev") {
                        // 处理从上一章跳转过来的情况
                    }

                    const positionParam = queryParams && queryParams.zrpos;
                    if (positionParam) {
                        readingProgress = Math.abs(parseFloat(positionParam));
                        readingProgress = Math.max(Math.min(1, readingProgress), 0);
                        history.pushState(null, null, initialHash);
                    }
                }
                if (body.hasClass("page-lr")) {
                    readingMode = "lr"
                    adjustLayout(readingProgress)
                } else {
                    readingMode = "ud"
                    if (readingProgress) {
                        body.scrollTop(body.height() * readingProgress - 32);
                    }
                }
                // 处理窗口大小变化和方向变化事件
                $(window).on("resize orientationchange", function () {
                    // 如果当前阅读模式为左右滑动模式，调整布局
                    if (readingMode === "lr") {
                        adjustLayout(readingProgress);
                    }
                });
            },
            handleLeftRightMode: handleLeftRightMode,
            handleUpDownMode: handleUpDownMode,
            flipLeft: flipLeft,
            flipRight: flipRight
        };
        module.exports = pageManager
        window.pageManager = pageManager
    }
});